﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class ForgetPwd : Form
    {
        public ForgetPwd()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {

            MessageBox.Show("别点老子，老子不会！", "警告");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string a = textBox1.Text.Trim();
            string connect = "server=LAPTOP-AS39K086\\MSSQLSERVER1;uid=HUANG;pwd=571193002;database=WinFrom";
            SqlConnection sqlConnection = new SqlConnection(connect);
            sqlConnection.Open();
            string sqlOrder = "select * from Login where phone='" + a + "' ";
            SqlCommand sqlCommand = new SqlCommand(sqlOrder, sqlConnection);
            var show = sqlCommand.ExecuteReader();
            if (show.Read())
            {
                string pwd = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$";
                Regex regex5 = new Regex(pwd);
                if (regex5.IsMatch(textBox2.Text) && textBox2.Text == textBox3.Text)
                {
                    string sqlUpdate = "update Login set pwd = '" + textBox2 + "' where phone = '" + textBox1 + "'";
                    SqlCommand sqlCommand1 = new SqlCommand(sqlUpdate, sqlConnection);
                    MessageBox.Show("密码修改成功，请返回登录", "提示");
                    sqlConnection.Close();
                    this.Close();
                }
                else if (!regex5.IsMatch(textBox2.Text))
                {
                    MessageBox.Show("密码至少包含：数字和英文，长度6-20", "提示");
                }
                else
                {
                    MessageBox.Show("确认密码需与密码一致", "提示");
                }
            }
            else
            {
                MessageBox.Show("密保电话不正确！", "警告");
            }

        }
    }
}
